import 'package:flutter/material.dart';

abstract class BaseItemPage extends StatelessWidget {
  late BuildContext context;

  BaseItemPage({super.key});

  @override
  Widget build(BuildContext context) {
    this.context = context;
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text("我是标题"),
        ),
        body: ListView(itemExtent: 60, children: getItems()),
      ),
    );
  }

  List<Widget> getItems();

  VoidCallback? defaultItemCallback;

  Widget addItemWidget(String name, VoidCallback onclick,
      {bool defaultItem = false}) {
    if (defaultItem) {
      defaultItemCallback = onclick;
    }
    return TextButton(onPressed: () => {onclick()}, child: Text(name));
  }

  void showMyDialog(Widget widget) {
    showModalBottomSheet(
        context: context,
        builder: (context) {
          return Container(
            width: double.infinity,
            height: MediaQuery.of(context).size.height / 2,
            alignment: Alignment.center,
            child: widget,
          );
        });
  }
}
